﻿@page "/FinancingFile"
@using Models;
<table>
    <p>
        <label>
            提示信息：@Message
        </label>
    </p>
    <tr>
        <td>身份证</td>
        <td>
            <InputFile OnChange="OnFileChange" />
        </td>
    </tr>
    <tr>
        <td>驾驶证</td>
        <td> <InputFile OnChange="OnFileChange" /></td>
    </tr>
    <tr>
        <td>最近3个月通讯记录</td>
        <td> <InputFile OnChange="OnFileChange" /></td>
    </tr>
    <tr>
        <td>个人信用报告</td>
        <td> <InputFile OnChange="OnFileChange" /></td>
    </tr>
    <tr>
        <td>定金不退同意书</td>
        <td> <InputFile OnChange="OnFileChange" /></td>
    </tr>
    <tr>
        <td>其他附件</td>
        <td><InputFile OnChange="OnFileChange" /></td>
    </tr>
</table>

@code {

    private Aaccessory BindingModel { get; set; } = new Aaccessory();

    private List<IBrowserFile> loadedFiles = new();
    private long maxFileSize = 1024 * 1024 * 24;
    private int maxAllowedFiles = 2;
    private bool isLoading;
    private string Message = string.Empty;
    private async Task OnFileChange(InputFileChangeEventArgs e)
    {

        // 这里可以添加处理上传文件的逻辑
        // 例如保存文件到服务器或者处理文件内容等
        isLoading = true;
        loadedFiles.Clear();
        foreach (var file in e.GetMultipleFiles(maxAllowedFiles))
        {
            try
            {
                loadedFiles.Add(file);
                
                string result = await FileHelpers.ProcessFormFile(file, maxFileSize);

                if (string.IsNullOrEmpty(result))
                {

                    Message = "上传失败！";
                }
                else
                   
                Message = "上传成功！";
            }
            catch (Exception ex)
            {
                Message = ex.Message;

            }
        }
        isLoading = false;

    }
}
